using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Goods.Dto;
using JTZY.Model.Goods;
using JTZY.Service.Goods.IGoodsService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-11-09
namespace JTZY.Admin.WebApi.Controllers.Goods
{
    /// <summary>
    /// 货品表
    /// </summary>
    [Verify]
    [Route("goods/Corecmsproducts")]
    public class CorecmsproductsController : BaseController
    {
        /// <summary>
        /// 货品表接口
        /// </summary>
        private readonly ICorecmsproductsService _CorecmsproductsService;

        public CorecmsproductsController(ICorecmsproductsService CorecmsproductsService)
        {
            _CorecmsproductsService = CorecmsproductsService;
        }

        /// <summary>
        /// 查询货品表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsproducts:list")]
        public IActionResult QueryCorecmsproducts([FromQuery] CorecmsproductsQueryDto parm)
        {
            var response = _CorecmsproductsService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询货品表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsproducts:query")]
        public IActionResult GetCorecmsproducts(int Id)
        {
            var response = _CorecmsproductsService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsproductsDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 更新货品表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsproducts:edit")]
        [Log(Title = "货品表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsproducts([FromBody] CorecmsproductsDto parm)
        {
            var modal = parm.Adapt<Corecmsproducts>().ToUpdate(HttpContext);
            var response = _CorecmsproductsService.UpdateCorecmsproducts(modal);

            return ToResponse(response);
        }

    }
}